<?php

class User_Form_Login extends Nuo_Form
{
	public function init()
	{

		$this -> setAction(Zend_Controller_Front::getInstance() -> getRouter() -> assemble(array(), 'user_login', true));

		$label = 'email/user';
		$validators = array();
		$loginMode = $this -> getLoginMode();

		// login by username only
		if ($loginMode == 2)
		{
			$label = 'user';
		}else
		if ($loginMode == 3)
		{
			$label = 'email';
			// login by email only
			$validators = array('EmailAddress');
		}

		$this -> addElement('Text', 'email', array(
				'label' => $label,
				'required' => true,
				'validators' => $validators
		));

		$this -> addElement('Password', 'password', array(
				'label' => 'password',
				'required' => true
		));

		$this -> addElement('button', '_submit', array(
				'label' => 'submit',
				'value' => 'submit',
				'type' => 'submit',
		));

	}

	/**
	 * login mode
	 * @see User_Plugin_Auth_DbTable
	 * @property int
	 */
	protected $_loginMode = 1;

	/**
	 * set login mode
	 */
	public function setLoginMode($value)
	{
		$this -> _loginMode = (int)$value;
		return $this;
	}

	public function getLoginMode()
	{
		return $this -> _loginMode;
	}

}
